/*
 * @lc app=leetcode.cn id=200 lang=javascript
 *
 * [200] 岛屿数量
 */

// @lc code=start
/**
 * @param {character[][]} grid
 * @return {number}
 */
var numIslands = function(grid) {
    let res=0
    let help=function(line,column){
        if(grid[line][column+1]==1){
            grid[line][column+1]=0
            help(line,column+1)
        }
        if(grid[line][column-1]==1){
            grid[line][column-1]=0
            help(line,column-1)
        }
        if(grid[line-1]&&grid[line-1][column]==1){
            grid[line-1][column]=0
            help(line-1,column)
        }
        if(grid[line+1]&&grid[line+1][column]==1){
            grid[line+1][column]=0
            help(line+1,column)
        }
    }
    for(let i=0;i<grid.length;i++){
        for(let j=0;j<grid[i].length;j++){
            if(grid[i][j]==1){
                help(i,j)
                res++
            }
        }
    }
   
    return res
};
// @lc code=end

